home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Utilities / Winter Shell 1.0d2 / Source / Libraries / TrapLib / TrapLib.c next >
Encoding:
C/C++ Source or Header  |  1993-11-24  |  1.0 KB  |  48 lines  |  [TEXT/KAHL]

  1. /* Trap numbers. Usually used when patching ToolBox routines.
  2.     
  3.     Revision History:
  4.     
  5.     91/04/19 AIH
  6.     - Added Gestalt trap and functions documented in IM-VI for checking
  7.     if a trap is available
  8.     
  9.     91/02/28 Ari Halberstadt (AIH)
  10.     - Created this file */
  11.  
  12. #include "TrapLib.h"
  13.  
  14. /* Functions for determining whether a trap is available. Based on
  15.     functions given in IM VI. */
  16.  
  17. /* return number of toolbox traps */
  18. short TrapNumToolbox(void)
  19. {
  20.     short result = 0;
  21.     
  22.     if (NGetTrapAddress(_InitGraf, ToolTrap) == NGetTrapAddress(0xAA6E, ToolTrap))
  23.         result = 0x0200;
  24.     else
  25.         result = 0x0400;
  26.     return(result);
  27. }
  28.  
  29. /* return the type of the trap */
  30. TrapType TrapTypeGet(short trap)
  31. {
  32.     return((trap & 0x0800) > 0 ? ToolTrap : OSTrap);
  33. }
  34.  
  35. /* true if the trap is available  */
  36. Boolean TrapAvailable(short trap)
  37. {
  38.     TrapType type;
  39.     
  40.     type = TrapTypeGet(trap);
  41.     if (type == ToolTrap) {
  42.         trap &= 0x07FF;
  43.         if (trap >= TrapNumToolbox())
  44.             trap = _Unimplemented;
  45.     }
  46.     return(NGetTrapAddress(trap, type) != NGetTrapAddress(_Unimplemented, ToolTrap));
  47. }
  48.